package com.aeoj.clientmanagement.utils.user;

import com.aeoj.clientmanagement.constant.SystemConstant;
import com.aeoj.clientmanagement.domain.user.SysUser;
import com.aeoj.clientmanagement.domain.user.vo.SysUserVO;
import com.aeoj.clientmanagement.enums.ResponseCodeEnum;
import com.aeoj.clientmanagement.exception.BusinessException;
import jakarta.servlet.http.HttpServletRequest;

/**
 * author: ZSM
 * time: 2025-04-21 14:16
 */
public class UserUtils {
    public static SysUserVO getLoginUser(HttpServletRequest request) {
        SysUserVO loginUser = (SysUserVO) request.getSession().getAttribute(SystemConstant.SESSION_REDIS_KEY);
        if (loginUser == null) {
            throw new BusinessException(ResponseCodeEnum.UNAUTHORIZED);
        }
        return loginUser;
    }

    public static Long getLoginUserId(HttpServletRequest request) {
        return getLoginUser(request).getUserId();
    }
}
